package command.usuario;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import model.Assistido;

import command.ICommand;

import dao.assinatura.AssistidoDAO;
import dao.fabrica.FabricaDAO;

public class DeletarAssistidoCommand implements ICommand {
	
	private String assistidoId;
	
	public String execute(HttpServletRequest request) throws ServletException, IOException {
		
		
		try {
			
			
			assistidoId = request.getParameter("a"); 
			if (assistidoId != null )
			{
				
				
			 
			 AssistidoDAO assistidoDAO = FabricaDAO.createAssistido();
		
			 Assistido assistido = assistidoDAO.getAssistidoById(Integer.parseInt(assistidoId));	

			 if (assistido != null){
				 assistidoDAO.deleteAssistido(Integer.parseInt(assistidoId));
			 }
			 
			}else{
				 return "/paginas/inicio.jsp?resultado=FALSE";
				 
			 }
			 
			
			
		} catch (SQLException e) {
			e.printStackTrace();
			return "/paginas/cadastro/cadastro_invalido.jsp";
		}
	return "/paginas/inicio.jsp?resultado=OK";

}
}
